var uid, daijiedan=0;
document.addEventListener('plusready',function(){
	var ws = plus.webview.currentWebview();
	PullToRefresh(ws);
	uid = plus.storage.getItem('uid');
	console.log(uid);
	showWating();
	$.ajax({
		type :"get",
		url :apiRoot+"?m=home&c=medicinal&a=orderList&uid="+uid,
		success :function(data){
			plus.storage.setItem('orderlist',data);
			var data = $.parseJSON(data);
			if(data){
//				console.log(JSON.stringify(data));
				var list = '';
				$.each(data, function(k,v) {
//					console.log(JSON.stringify(v));
					if(v.status == 1){
						daijiedan++;
					}
					list += '<div class="mui-table-view table-view-cell bbs-ico margin-bottom-5" data-id="'+v.id+'">'+
								'<div class="overflow-h">'+
									'<i><img src="'+getAvatar(v.binfo.avatar)+'"/></i>'+
									'<div>'+
										'<li>'+
											'<span>'+v.binfo.name+'</span>'+
											'<span class="mui-h6 inquiry-right">';
									switch(v.status){
										case '0':list += '待付款';break;
										case '1':list += '待接单';break;
										case '2':list += '待收货';break;
										case '3':list += '已完成';break;
									}
									list += '</span>'+
										'</li>'+
										'<li class="mui-h6 ">'+
											'<span>'+v.ztime+'</span>'+
										'</li>'+
									'</div>'+
								'</div>'+
							'</div>';
				});
//				alert('您有'+daijiedan+'条药单用户已付款');
				$('.orderList').html(list);
				plus.nativeUI.closeWaiting();
				$('.bbs-ico').click(function(){
					var id = $(this).attr('data-id');
//					console.log(id);
					goDetail(id);
				})
			}else{
				toast('暂无订单信息！');
			}
		},
		error :function(e){
			console.log(JSON.stringify(e));
			errortoast();
			var dat = plus.storage.getItem('orderlist');
			var data = $.parseJSON(dat);
			if(data){
				console.log(JSON.stringify(data));
				var list = '';
				$.each(data, function(k,v) {
					list += '<div class="mui-table-view table-view-cell bbs-ico margin-bottom-5" data-id="'+v.id+'">'+
								'<div class="overflow-h">'+
									'<i><img src="'+getAvatar(v.binfo.avatar)+'"/></i>'+
									'<div>'+
										'<li>'+
											'<span>'+v.binfo.name+'</span>'+
											'<span class="mui-h6 inquiry-right">';
									switch(v.status){
										case '0':list += '待付款';break;
										case '1':list += '待接单';break;
										case '2':list += '待收货';break;
										case '3':list += '已完成';break;
									}
									list += '</span>'+
										'</li>'+
										'<li class="mui-h6 ">'+
											'<span>'+v.ztime+'</span>'+
										'</li>'+
									'</div>'+
								'</div>'+
							'</div>';
				});
				$('.orderList').html(list);
				$('.bbs-ico').click(function(){
					var id = $(this).attr('data-id');
					goDetail(id);
				})
			}
		}
	});
	
},false)
//进入订单详情->病例（订单）Id
function goDetail(id){
	goNewPage('free-information-order-1.html',{aid:id});
}
